package com.example.controller;

import com.example.bean.Depart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author 徐文祥
 * @since 2023/12/09 18:27
 */
@RestController
@RequestMapping("/consumer/depart")
public class DepartController {

    @Autowired
    RestTemplate restTemplate;


    private String URL="http://provider-depart/provider/depar/";
    @PostMapping()
    public boolean saveHandler(@RequestBody Depart depart){
        return  restTemplate.postForObject(URL,depart, Boolean.class);
    }

    @DeleteMapping("/{id}")
    public void deleteHandler(@PathVariable("id") Integer id){
          restTemplate.delete(URL+id);
    }

    @PutMapping("/")
    public void updateHanlder(@RequestBody Depart depart){

        restTemplate.put(URL,depart);
    }

    @GetMapping("/{id}")
    public Depart getHandler(@PathVariable("id") Integer id){
        return restTemplate.getForObject(URL + id, Depart.class);
    }

    @GetMapping("/list")
    public List<Depart> listHandler(){
        List forObject = restTemplate.getForObject(URL, List.class);
        return forObject;
    }
}
